<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@include file="/context/mytags.jsp"%>
<t:base type="jquery,easyui,tools,DatePicker"></t:base>
<div class="easyui-layout" fit="true">
    <div region="center" style="padding:1px;">
        <t:datagrid name="zyEquipmentTypeList" checkbox="false" fitColumns="false" title="备件类型" treegrid="true" pagination="false" onDblClick="dbClick"
                    actionUrl="cbsDelinerController.do?dataGridOfChooseEquipmentType" idField="id" fit="true" queryMode="group">
            <t:dgCol title="主键"  field="id"  hidden="true" treefield="id"	 width="120"></t:dgCol>
            <t:dgCol title="机型名"  field="typeDesc" 		treefield="text"	width="250"></t:dgCol>
        </t:datagrid>
    </div>
    <input id="wuid" hidden="hidden" value="${wuId}">
</div>
<script src = "webpage/com/zybk/zy_em_valida_rule/zyEmValidaRuleList.js"></script>
<script type="text/javascript">
    function dbClick(node){
        <%
              String uuid = request.getParameter("uuid");
              String id = request.getParameter("id");
        %>
        var uuid = '<%=uuid%>';//输出s2给js变量s
        var applyId = '<%=id%>';
        /*aid = decodeURI(aid)*/
        if(!node.hasLeaf){
            console.log("typeDesc:"+node.id)
            console.log("wid:"+$('#wuid').val())
            console.log("applyId:"+applyId)
            //console.log("typeDesc1:"+node.equipmentType.typeDesc)
            if(applyId!="null"){
                var id=node.id;
                $("#"+applyId+"typeDesErr",top.myWindow.document).hide();
                if(id==$('#wuid').val()){
                    $("#"+applyId+"in",top.myWindow.document).show();
                    $("#"+applyId+"in",top.myWindow.document).val('');
                    $("#"+applyId+"isTrack",top.myWindow.document).val('');
                    $("#"+applyId+"itemId",top.myWindow.document).hide();
                    $("#"+applyId+"itemIdErr",top.myWindow.document).hide();
                    $("#"+applyId+"itemId",top.myWindow.document).val("");
                    $("#"+applyId,top.myWindow.document).val(node.id);
                    $("#"+applyId+"typeDes",top.myWindow.document).val(node.text);
                    frameElement.api.close();
                }else{
                    $("#"+applyId+"in",top.myWindow.document).val("")
                    $("#"+applyId,top.myWindow.document).val(node.id);
                    $("#"+applyId+"typeDes",top.myWindow.document).val(node.text);
                    $.ajax({
                        url: "cbsDelinerController.do?getItemId",
                        data: {
                            "id":id
                        },
                        cache: false,
                        dataType: 'json',
                        type: 'POST',
                        error : function() {// 请求失败处理函数
                        },
                        success : function(data) {
                            if(data==null){
                                $("#"+applyId+"itemId",top.myWindow.document).hide();
                                $("#"+applyId+"in",top.myWindow.document).show();
                                /* $("#"+applyId+"span",top.myWindow.document).html("<input type='text'>");*/
                            }else{
                                $("#"+applyId+"itemId",top.myWindow.document).html("");
                                $("#"+applyId+"itemId",top.myWindow.document).show();
                                $("#"+applyId+"in",top.myWindow.document).hide();
                                var html="";
                                html+="<option value=''>--请选择备件号--</option>";
                                for(a in data){
                                    html+="<option value='"+data[a].id+"'>"+data[a].item+"</option>"
                                }
                                $("#"+applyId+"itemId",top.myWindow.document).append(html);
                            }
                            frameElement.api.close();
                        }
                    });
                }

            }else{
                var id=node.id;
                $("#"+uuid+"typeDesErr",top.myWindow.document).hide();
                if(id==$('#wuid').val()){
                    $("#"+uuid+"in",top.myWindow.document).show();
                    $("#"+uuid+"in",top.myWindow.document).val('');
                    $("#"+uuid+"isTrack",top.myWindow.document).val('');
                    $("#"+uuid+"itemId",top.myWindow.document).hide();
                    $("#"+uuid+"itemId",top.myWindow.document).val("")
                    $("#"+uuid,top.myWindow.document).val(node.id);
                    $("#"+uuid+"typeDes",top.myWindow.document).val(node.text);
                    frameElement.api.close();
                }else {
                    $("#"+uuid+"in",top.myWindow.document).val("")
                    $("#"+uuid,top.myWindow.document).val(node.id);
                    $("#"+uuid+"typeDes",top.myWindow.document).val(node.text);
                    $.ajax({
                        url: "cbsDelinerController.do?getItemId",
                        data: {
                            "id":id
                        },
                        cache: false,
                        dataType: 'json',
                        type: 'POST',
                        error : function() {// 请求失败处理函数
                        },
                        success : function(data) {
                            if(data==null){
                                $("#"+uuid+"itemId",top.myWindow.document).hide();
                                $("#"+uuid+"in",top.myWindow.document).show();
                                /*$("#"+uuid+"span",top.myWindow.document).html("<input type='text'>");*/
                            }else{
                                $("#"+uuid+"itemId",top.myWindow.document).html("");
                                $("#"+uuid+"itemId",top.myWindow.document).show();
                                $("#"+uuid+"in",top.myWindow.document).hide();
                                var html="";
                                html+="<option value=''>--请选择备件号--</option>";
                                for(a in data){
                                    html+="<option value='"+data[a].id+"'>"+data[a].item+"</option>"
                                }
                                $("#"+uuid+"itemId",top.myWindow.document).append(html);
                            }
                            frameElement.api.close();
                        }
                    });
                }
            }
        }else{
            tip("请选择正确的机型");
        }
    }
</script>